package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.DeviceManage;
import com.ruoyi.manage.service.IDeviceManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 器械信息Controller
 * 
 * @author liuyangyang
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/manage/devicemanage")
public class DeviceManageController extends BaseController
{
    @Autowired
    private IDeviceManageService deviceManageService;

    /**
     * 查询器械信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceManage deviceManage)
    {
        startPage();
        List<DeviceManage> list = deviceManageService.selectDeviceManageList(deviceManage);
        return getDataTable(list);
    }

    /**
     * 导出器械信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:export')")
    @Log(title = "器械信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceManage deviceManage)
    {
        List<DeviceManage> list = deviceManageService.selectDeviceManageList(deviceManage);
        ExcelUtil<DeviceManage> util = new ExcelUtil<DeviceManage>(DeviceManage.class);
        util.exportExcel(response, list, "器械信息数据");
    }

    /**
     * 获取器械信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return success(deviceManageService.selectDeviceManageByDeviceId(deviceId));
    }

    /**
     * 新增器械信息
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:add')")
    @Log(title = "器械信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceManage deviceManage)
    {
        return toAjax(deviceManageService.insertDeviceManage(deviceManage));
    }

    /**
     * 修改器械信息
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:edit')")
    @Log(title = "器械信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceManage deviceManage)
    {
        return toAjax(deviceManageService.updateDeviceManage(deviceManage));
    }

    /**
     * 删除器械信息
     */
    @PreAuthorize("@ss.hasPermi('manage:devicemanage:remove')")
    @Log(title = "器械信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(deviceManageService.deleteDeviceManageByDeviceIds(deviceIds));
    }
}
